//
//  LSMineTableViewAddSectionHeaderCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/28.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSMineTableViewAddSectionHeaderCell.h"

@interface LSMineTableViewAddSectionHeaderCell ()
@property (nonatomic, strong) UIView *customerContentView;
@property (nonatomic, strong) UIImageView *mainImageView;
@property (nonatomic, strong) UILabel *mainTitleLabel;
@property (nonatomic, strong) UIImageView *rightArrowImageView;
@end

@implementation LSMineTableViewAddSectionHeaderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = hexColor(EEEEEE);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.customerContentView];
        [self.customerContentView addSubview:self.mainImageView];
        [self.customerContentView addSubview:self.mainTitleLabel];
        [self.customerContentView addSubview:self.rightArrowImageView];
        WS
        [self.mainImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.customerContentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(0, 35));
        }];
        [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.customerContentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
        }];
    }
    return self;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    WS
    if (highlighted) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    WS
    if (selected) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)setImageName:(NSString *)imageName {
    _imageName = imageName;
    WS
    if (![imageName isEqualToString:@""]) {
        self.mainImageView.image = [UIImage imageNamed:imageName];
        [self.mainImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.customerContentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(44/2, 44/2));
        }];
        [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.mainImageView.mas_right).with.offset(10);
            make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
        }];
    } else {
        self.mainImageView.image = nil;
        [self.mainImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.customerContentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(0, 44/2));
        }];
        [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.customerContentView.mas_left).with.offset(15);
            make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
        }];
    }
}

- (void)setTitleLabelName:(NSString *)titleLabelName {
    _titleLabelName = titleLabelName;
    self.mainTitleLabel.text = titleLabelName;
}

- (UIImageView *)mainImageView {
    if (!_mainImageView) {
        _mainImageView = [[UIImageView alloc] init];
    }
    return _mainImageView;
}

- (UILabel *)mainTitleLabel {
    if (!_mainTitleLabel) {
        _mainTitleLabel = [[UILabel alloc] init];
        _mainTitleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:16];
        _mainTitleLabel.textColor = hexColor(666666);
    }
    return _mainTitleLabel;
}

- (UIImageView *)rightArrowImageView {
    if (!_rightArrowImageView) {
        _rightArrowImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"jiantou"] changeWithNewTintColor:hexColor(999999)]];
        _rightArrowImageView.center = CGPointMake(ScreenWidth-20, (LSMineTableViewAddSectionHeaderCellHeight-15)/2);
    }
    return _rightArrowImageView;
}

- (UIView *)customerContentView {
    if (!_customerContentView) {
        _customerContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 15, ScreenWidth, LSMineTableViewAddSectionHeaderCellHeight-15)];
        _customerContentView.backgroundColor = UIColor.whiteColor;
    }
    return _customerContentView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

@end
